package com.lovo.pz.role;

import com.lovo.pz.util.GameUtil;
import com.lovo.pz.window.GamePanel;

import java.awt.*;
import java.util.List;

/**
 * 除草车角色
 * @author 白德柯
 *
 */
public class CarRole extends BaseRole{
    public CarRole(Component component){
        super(component);
    }
    @Override
    public void initRole() {
        setRoleX(60);
        setMoveLength(10);
        setRoleWidth(GameUtil.carImage.getWidth(getComponent()));
        setRoleHeight(GameUtil.carImage.getHeight(getComponent()));
    }

    @Override
    public void paintRole(Graphics g) {
        g.drawImage(GameUtil.carImage,getRoleX(),getRoleY(),getComponent());
    }

    @Override
    public void action() {
        GamePanel gamePanel = (GamePanel) getComponent();
        List<ZombieRole> zombieRoleList = gamePanel.getZombieRoleList();
        for(int i = 0;i < zombieRoleList.size();i++){
            if(GameUtil.checkImpact(this,zombieRoleList.get(i))){
                setRunStatus(CAR_RUN);
                zombieRoleList.get(i).setHp(0);
            }
        }
        if(getRunStatus() == CAR_RUN){
            setRoleX(getRoleX() + getMoveLength());
            if(getRoleX() > 1400){
                setRunStatus(ROLE_END);
            }
        }
    }
}
